<template>
  <div class="account-table-wrap">
    <el-table
      :data="tableData"
      style="width: 100%"
      :border="true"
      :fit="true"
      :stripe="true"
      size="mini"
      align="center">
      <el-table-column
        prop="formatId"
        label="id"
        min-width="80"
        align="center">
      </el-table-column>

      <el-table-column
      :show-overflow-tooltip="true"
        prop="auxiliaryParts_number"
        label="辅件编号"
        min-width="120"
        align="center">
      </el-table-column>

      <el-table-column
      :show-overflow-tooltip="true"
        prop="auxiliaryParts_name"
        label="辅件名称"
        min-width="110"
        align="center">
      </el-table-column>

      <el-table-column
      :show-overflow-tooltip="true"
        prop="format_name"
        label="规格/型号"
        min-width="110"
        align="center">
      </el-table-column>

      <el-table-column
        prop="auxiliaryParts_unit"
        label="单位"
        min-width="80"
        align="center">
      </el-table-column>

      <el-table-column
        prop="max"
        label="库存上限"
        min-width="100"
        align="center">
      </el-table-column>

      <el-table-column
        prop="min"
        label="库存下限"
        min-width="100"
        align="center">
      </el-table-column>

      <el-table-column
        prop="stock"
        label="库存量"
        min-width="120"
        align="center">
        <template slot-scope="scope">
          <div class="tit-pic">
            <div class="pic" :class="scope.row.stock>scope.row.max?'a':scope.row.stock<scope.row.min?'b':''">{{scope.row.stock}}</div>
          </div>
        </template>
      </el-table-column>

      <el-table-column label="操作"
      min-width="180"
      align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            plain
            type="success"
            @click="changeMaxMin(scope.row)">修改上下限</el-button>
        </template>
      </el-table-column>
    </el-table>
    <deleteConfirm v-if="showMask" @closeDelete="closeDelete" @deleteConfirm="deleteConfirm"></deleteConfirm>

      <el-dialog  class="max" v-if="changeMax" title="修改库存上下限" center :visible="true" width="400px" @close="maxClose">
      <div class="max-in">
        <div>修改上限 : </div>
        <el-input :style="{'width':'250px'}" size="mini" class="search" clearable v-model="max" placeholder="请输入单价"></el-input>
      </div>
      <div class="max-in">
        <div>修改下限 : </div>
        <el-input :style="{'width':'250px'}" size="mini" class="search" clearable v-model="min" placeholder="请输入单价"></el-input>
      </div>
      <span slot="footer" class="dialog-footer">
      <el-button @click="maxClose">取 消</el-button>
      <el-button type="primary" @click="maxConfirm">确 定</el-button>
    </span>
  </el-dialog>

  </div>
</template>
<script lang="ts">
import Vue from 'vue';
import Component from 'vue-class-component';
import { Prop, Emit } from 'vue-property-decorator';
import deleteConfirm from '@/components/deleteConfirm.vue';
import ajaxResquest from '@/api/apiRequest';
@Component({
  components: {
    deleteConfirm
  }
})
export default class AccessStockTable extends Vue {
  @Prop({
    type: Array
  })
  tableData!: any[];
  showMask: boolean = false;
  maxId!: number;
  deleteRes!: ajaxResquest;
  maxRes!: ajaxResquest;
  changeMax: boolean = false;
  max: string = '';
  min: string = '';
  tableEdit(row: any) {
    this.$to('accessListCreate', { edit: true, id: row.id });
  }
  mounted() {
    this.deleteRes = new ajaxResquest('/materials/delMaterials');
    this.maxRes = new ajaxResquest('/auxiliaryparts/updateAuxiliaryMaxMin');
  }
  changeMaxMin(row: any) {
    console.log(row);
    this.maxId = row.formatId;
    if (row.max) {
      this.max = row.max;
      this.min = row.min;
    }
    this.changeMax = true;
    // this.showMask = true;
  }
  maxClose() {
    this.changeMax = false;
  }
  maxConfirm() {
    this.maxRes
      .getFunction({
        formatId: this.maxId,
        max: this.max,
        min: this.min
      })
      .then((res: any) => {
        if (res.data.code === 1) {
          this.changeMax = false;
          this.getData();
        }
      });
  }
  closeDelete(row: object) {
    this.showMask = false;
  }
  deleteConfirm() {
    console.log('done');
    this.deleteRes.getFunction({ materialsId: this.maxId }).then((res:any) => {
      if (res.data.code === 1) {
        this.getData();
        this.showMask = false;
      }
    });
  }
  @Emit('getData')
  getData() {}
}
</script>
<style lang="less">
.account-table-wrap {
  .max {
    .el-dialog__title {
      font-size: 16px;
    }
    .el-dialog__body {
      padding: 10px;
    }
  }
  .max-in {
    display: flex;
    align-items: center;
    flex-direction: row;
    margin-top: 10px;
  }
  .a {
    color: #66cccc;
  }
  .b {
    color: #cc0000;
  }
}
</style>
